//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - SaaS Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================


using System;
using System.Collections.Generic;
using System.Text;
using ConfigurationWizard.Configuration;
using System.Collections.ObjectModel;
using ConfigurationWizard.Validation;

namespace ConfigurationWizard.Setup
{
    public class SetupConfigurationReader
    {
        private SetupSection section;

        public SetupConfigurationReader(SetupSection section)
        {
            this.section = section;
        }

        public Collection<Task> GetTasks()
        {
            Collection<Task> tasks = new Collection<Task>();

            foreach (TaskElement element in section.Tasks)
            {
                Task task = ConfigFactory.CreateTask(element);
                tasks.Add(task);
            }
            
            return tasks;
        }

        public Collection<Preview> GetPreview()
        {
            Collection<Preview> previews = new Collection<Preview>();

            foreach (PreviewElement element in section.Previews)
            {
                Preview preview = ConfigFactory.CreatePreview(element);
                previews.Add(preview);
            }

            return previews;
        }

        public Collection<Task> GetTasksForThisOS()
        {
            Collection<Task> tasks = new Collection<Task>();
            String buildNumber = DependencyConfigurationReader.GetOSBuildNumber();
            foreach (TaskElement element in section.Tasks)
            {
                Task task = ConfigFactory.CreateTask(element);
                if(task.IsEnableForThisOS(buildNumber))
                    tasks.Add(task);
            }
            return tasks;
        }

        public Collection<Preview> GetPreviewForThisOS()
        {
            Collection<Preview> previews = new Collection<Preview>();
            String buildNumber = DependencyConfigurationReader.GetOSBuildNumber();
            foreach (PreviewElement element in section.Previews)
            {
                Preview preview = ConfigFactory.CreatePreview(element);
                if( preview.IsEnableForThisOS(buildNumber))
                    previews.Add(preview);
            }

            return previews;
        }
    }
}
